﻿using Microsoft.VisualBasic;
using MiniExcelLibs;
using MiniExcelLibs.Attributes;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using static System.Runtime.InteropServices.JavaScript.JSType;

namespace ConsoleApp10
{
    class Tests
    {
        public string Name { get; set; }
        public Tests()
        {

        }
    }

    internal class Program
    {
        static void Main(string[] args)
        {
            string input = "A.培训";
            string output = Regex.Replace(input, @"^A\.", "");
            Console.WriteLine(output); // 输出: "培训"
            TestCar2.Tets();
            //TestCar.Test();
            using (Stream stream = File.OpenRead("C:\\Users\\hu\\Desktop\\大庆巡游出租车区域题库(2)(2).xlsx"))
            {
                List<string> list = new List<string>();
                var questionInputs = stream.Query<QuestionImportDataV1>().ToList();
                if (questionInputs == null || questionInputs.Count == 0)
                {
                    return;
                }
                List<QuestionInput> questions = new List<QuestionInput>();
                List<QuestionOutData> questions2 = new List<QuestionOutData>();
                foreach (var questionInput in questionInputs)
                {
                    //var strings = questionInput.Content.Split("\n");
                    //list.AddRange(strings);
                    string[] lines = questionInput.Content.Split('\n');
                    foreach (string line in lines)
                    {
                        Match match = Regex.Match(line, @"^(\d+) 、(.+)\((\√|X)\)$");
                        if (match.Success)
                        {
                            int number = int.Parse(match.Groups[1].Value);
                            string content = match.Groups[2].Value.Trim();
                            string result = match.Groups[3].Value;
                            Console.WriteLine($"{number} 、{content}({result})");
                            QuestionOutData questionOutData = new QuestionOutData()
                            {
                                Answer = (result == "√" ? "A" : "B") == "A" ? "1" : "2",
                                Content = content,
                                Number = number,
                                OptionA = "A",
                                OptionB = "B",
                                OptionC = "",
                                OptionD = "",

                            };

                            questions2.Add(questionOutData);
                            QuestionInput questionInput1 = new QuestionInput();
                            List<WxOptionsInfo> wxOptionsInfos = new List<WxOptionsInfo>();
                            wxOptionsInfos.Add(new WxOptionsInfo()
                            {
                                OptionTitle = "A",
                                OptionContent = "对"
                            });
                            wxOptionsInfos.Add(new WxOptionsInfo()
                            {
                                OptionTitle = "B",
                                OptionContent = "错"
                            });
                            questionInput1.Id = number;
                            questionInput1.Contents = content;
                            questionInput1.Answer = result == "√" ? "A" : "B";
                            questionInput1.Options = JsonConvert.SerializeObject(wxOptionsInfos);
                            questions.Add(questionInput1);
                        }
                        else
                        {
                            Console.WriteLine("匹配失败");
                        }
                    }
                }
                var sss = questions.GroupBy(a => a.Id);
                foreach (var ss in sss)
                {
                    Console.WriteLine(ss.Key + "  " + ss.Count());
                }
                //      MiniExcel.SaveAs($"{Directory.GetCurrentDirectory()}output.xlsx", questions2);
                //using (var strem = File.Create("C:\\Users\\hu\\Desktop\\output.xlsx"))
                //{
                //    strem.SaveAs(list);
                //}


                //List<QuestionImportDataV1> inputs= new List<QuestionImportDataV1>();
                //foreach (var item in questionInputs)
                //{
                //    QuestionInput questionInput = new QuestionInput();
                //    questionInput.WorkType = "危险货物装卸试题";
                //    questionInput.Contents = item.Content;
                //    List <WxOptionsInfo> wxOptions=new List<WxOptionsInfo>();
                //    if (!string.IsNullOrEmpty(item.OptionA))
                //    {
                //        wxOptions.Add(new WxOptionsInfo()
                //        {
                //            OptionTitle = "A",
                //            OptionContent = item.OptionA,
                //        });

                //    }
                //    if (!string.IsNullOrEmpty(item.OptionB))
                //    {
                //        wxOptions.Add(new WxOptionsInfo()
                //        {
                //            OptionTitle = "B",
                //            OptionContent = item.OptionB,
                //        });

                //    }
                //    if (!string.IsNullOrEmpty(item.OptionC))
                //    {
                //        wxOptions.Add(new WxOptionsInfo()
                //        {
                //            OptionTitle = "C",
                //            OptionContent = item.OptionC,
                //        });
                //    }
                //    if (!string.IsNullOrEmpty(item.OptionD))
                //    {
                //        wxOptions.Add(new WxOptionsInfo()
                //        {
                //            OptionTitle = "D",
                //            OptionContent = item.OptionD,
                //        });
                //    }
                //    string answwer = "";
                //    switch (item.Answer)
                //    {
                //        case "1":
                //            answwer = "A";
                //            break;
                //        case "2":
                //            answwer = "B";
                //            break;
                //        case "3":
                //            answwer = "C";
                //            break;
                //        case "4":
                //            answwer = "D";
                //            break;
                //        default:
                //            break;
                //    }
                //    questionInput.Answer = answwer;
                //    questionInput.Options = JsonConvert.SerializeObject(wxOptions);
                //    inputs.Add(questionInput);
                //}

            }
        }
    }
    public class QuestionInput
    {
        #region 实体成员
        public long Id { get; set; }
        /// <summary>
        /// 准操项目
        /// </summary>	
        public string WorkType { get; set; }
        /// <summary>
        /// 题目类型 1判断题  2单选题  3多选题 
        /// </summary>		
        public int QuestionType { get; set; }
        /// <summary>
        /// 题干内容
        /// </summary>		
        [ExcelColumnName("题目")]
        public string Contents { get; set; }
        /// <summary>
        /// 问题答案
        /// </summary>		

        public string Answer { get; set; }
        /// <summary>
        /// 选项  JSON格式
        /// </summary>		
        public string Options { get; set; }
        /// <summary>
        /// 题目解析-知识点 
        /// </summary> 
        public string Explain { get; set; }

        /// <summary>
        /// 启用禁用  1：启用 0：禁用
        /// </summary>	
        public int EnabledMark { get; set; } = 1;

        public int IsInner { get; set; } = 0;

        #endregion
    }


    public class WxOptionsInfo
    {
        /// <summary>
        ///  A B C D
        /// </summary>
        public string OptionTitle { get; set; }
        /// <summary>
        /// 考试内容
        /// </summary>
        public string OptionContent { get; set; }

    }
    public class QuestionImportData
    {
        [ExcelColumnName("序号")]
        public int? Number { get; set; }
        [ExcelColumnName("题型")]
        public string QuestionType { get; set; } = "单选题";
        [ExcelColumnName("题目")]
        public string Content { get; set; }
        [ExcelColumnName("答案1")]
        public string OptionA { get; set; }
        [ExcelColumnName("答案2")]
        public string OptionB { get; set; }
        [ExcelColumnName("答案3")]
        public string OptionC { get; set; }
        [ExcelColumnName("答案4")]
        public string OptionD { get; set; }

        [ExcelColumnName("正确答案")]
        public string Answer { get; set; }
    }

    public class QuestionImportDataV1
    {
        [ExcelColumnName("大庆市出租车区域科目题库")]
        public string Content { get; set; }


    }
    public class QuestionOutData
    {
        [ExcelColumnName("序号")]
        public int? Number { get; set; }
        [ExcelColumnName("题型")]
        public string QuestionType { get; set; } = "单选题";
        [ExcelColumnName("题目")]
        public string Content { get; set; }
        [ExcelColumnName("答案1")]
        public string OptionA { get; set; }
        [ExcelColumnName("答案2")]
        public string OptionB { get; set; }
        [ExcelColumnName("答案3")]
        public string OptionC { get; set; }
        [ExcelColumnName("答案4")]
        public string OptionD { get; set; }

        [ExcelColumnName("正确答案")]
        public string Answer { get; set; }

        [ExcelColumnName("区域")]
        public string ApplyArea { get; set; } = "全国";
    }
    public class QuestionImportDataV2
    {
        [ExcelColumnName("序号")]
        public int? Number { get; set; }
        [ExcelColumnName("题干")]
        public string Content { get; set; }
        [ExcelColumnName("题型")]
        public string QuestionType { get; set; } = "单选题";

        [ExcelColumnName("备选答案A")]
        public string OptionA { get; set; }
        [ExcelColumnName("备选答案B")]
        public string OptionB { get; set; }
        [ExcelColumnName("备选答案C")]
        public string OptionC { get; set; }
        [ExcelColumnName("备选答案D")]
        public string OptionD { get; set; }

        [ExcelColumnName("答案")]
        public string Answer { get; set; }


    }
}
